var visitTable;
function getVisitLogList() {
	if (typeof visitTable !== 'undefined') {
		visitTable.fnPageChange('first');
		return;
	}
	var i = 1;
	visitTable = $("#visitLogList")
			.DataTable(
					{
						"sAjaxSource" : _path + "/visitLog/queryByPage",
						"fnServerParams" : function(aoData) {
							aoData.push(
									{"name" : "liveId","value" : $("#liveId").val()},
									{"name" : "userNickName","value" : $("#userNickName").val()},
									{"name" : "operateDesc","value" : $("#operateDesc").val()},
									{ "name": "fromDate", "value": $("#fromDate").val() },
						            { "name": "toDate", "value": $("#toDate").val() }
							);
						},
						"sServerMethod" : "POST",
						"sAjaxDataProp" : "dataList",
						"fnCreatedRow" : function() {
							i++;
						},
						"fnPreDrawCallback" : function() {
							i = 1;
						},
						"aoColumns" : [
								{
									"sTitle" : "序号",
									"sWidth" : "2%",
									"mData" : function() {
										return i;
									}
								},
								{
									"sTitle" : "直播ID",
									"mData" : "liveId",
									"sWidth" : "2%"
								},
								{
									"sTitle" : "直播名称",
									"mData" : "live.name",
									"sWidth" : "10%"
								},
								{
									"sTitle" : "播放状态",
									"mData" : "live.status",
									"sWidth" : "2%",
										"mRender" : function(data) {
											var status = '';
											switch (data) {
											case '0':
												status = '片花';
												break;
											case '1':
												status = '直播';
												break;
											case '2':
												status = '回放';
												break;
											}
											return status;
										}
								},
								{
									"sTitle" : "用户昵称",
									"mData" : "userNickName",
									"sWidth" : "6%"
								},
								{
									"sTitle" : "状态",
									"mData" : "status",
									"sWidth" : "2%",
									"mRender" : function(data) {
										var status = '';
										switch (data) {
										case '1':
											status = '在线';
											break;
										case '2':
											status = '离线';
											break;
										}
										return status;
									}
								},
								{
									"sTitle" : "操作描述",
									"mData" : "operateDesc",
									"sWidth" : "10%"
								},
								{
									"sTitle" : "创建时间",
									"mData" : "createTime",
									"sWidth" : "6%"
								},
								{
									"sTitle" : "操作",
									"sWidth" : "3%",
									"mData" : function(data) {
													
										var	status = '&nbsp;<a href="javascript:inquiry('
													+ data.id
													+ ');"  class="btn default btn-xs red"><i class="fa fa-trash-o" title="删除"></i></a>';
								
										return status;
									}
								} 
								]
					});
}


//获取所有直播的信息
function queryAllLive(lid){
	 $.ajax({										
		    url: _path + "/chat/queryAllLive",
		    type: "POST",
		    dataType: "json",
		    async: false,
		    success: function(jsonMap) {
		    	var list = jsonMap.dataList;
		        if(list.length>0){
		        	for(var i=0;i<list.length;i++){
						var live = list[i];
						var op ="";
						  if ( lid == live.id) {
							  op = "<option value="+live.id+" selected>"+live.name+"</option>";
						  }else{
							  op = "<option value="+live.id+" >"+live.name+"</option>";
						  }
						$("#liveId").append(op);
		        	}
		        }
		    }
		});
}


function inquiry(id) {

	layer.confirm('您确定要删除吗？', {
		btn : [ '确定', '取消' ]
	// 按钮
	}, function() {
		location.href = _path + "/visitLog/del/" + id;
	}, function() {

	});
}